package com.cs.spzx.manager.controller;

import com.cs.spzx.manager.service.UserService;
import com.cs.spzx.model.dto.system.AssginRoleDto;
import com.cs.spzx.model.dto.system.SysUserDto;
import com.cs.spzx.model.entity.system.SysRole;
import com.cs.spzx.model.entity.system.SysUser;
import com.cs.spzx.model.vo.common.Result;
import com.cs.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Stone
 * @version 1.0.1
 * @date 2024/12/31
 */
@RestController
@RequestMapping(value = "/admin/system/sysUser")
@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
public class SysUserController {

    @Autowired
    private UserService userService ;

    @PostMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysRole>> findByPage(@RequestBody SysUserDto sysUserDto,
                                                @PathVariable(value = "pageNum") Integer pageNum,
                                                @PathVariable(value = "pageSize") Integer pageSize){
        PageInfo<SysUser> pageInfo = userService.findByPage(sysUserDto , pageNum , pageSize);
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS);
    }

    @PostMapping(value = "/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser) {
        userService.saveSysUser(sysUser) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @PutMapping(value = "/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser) {
        userService.updateSysUser(sysUser) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @DeleteMapping(value = "/deleteById/{userId}")
    public Result deleteById(@PathVariable(value = "userId") Long userId) {
        userService.deleteById(userId) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginRoleDto assginRoleDto) {
        userService.doAssign(assginRoleDto) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
}
